import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/shared/shared.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'state.dart';

class UserPrivacyDownloadInfoController extends GetxController {
  final UserPrivacyDownloadInfoState state = UserPrivacyDownloadInfoState();

  TextEditingController emailController = TextEditingController();

  @override
  void applyDownload() {
    showGeneralDialog(
      context: Get.context!,
      pageBuilder: (BuildContext buildContext, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        return TDInputDialog(
          textEditingController: emailController,
          title: '填写电子邮箱',
          contentWidget: Column(
            children: [
              Gaps.vGap8,
              Text('文件准备好后，下载链接将会发送至该邮箱中，下载有效期限为7天。该文件一般需要三天的准备时间'),
              Gaps.vGap16,
              Text(
                '涉及到个人隐私信息，请确认邮箱是否正确，提交后不可更改',
                style: TextStyle(color: Colors.redAccent),
              )
            ],
          ),
          hintText: '请输入邮箱',
          rightBtn: TDDialogButtonOptions(
            title: '确定',
            action: () {
              if (UtilValidate.checkIsEmail(emailController.text)) {
                SmartDialog.showNotify(msg: '提交成功', notifyType: NotifyType.error);
                Get.back();
              } else {
                SmartDialog.showNotify(msg: '请输入正确的邮箱', notifyType: NotifyType.error);
              }
            },
          ),
        );
      },
    );
  }
}
